var myCountChoose = 0;
var nowMoney;
$(function(){
	
	$('.cashToChoose').on('tap',function(){
		var newMyCountChoose = $(this).attr('data-id')
		myCountChoose = newMyCountChoose;
	});
	
	//余额
	balance({
		c_user_id:CD.geturl().business
	},function(data){
		nowMoney = data.data.balance;
		console.log(nowMoney)
	});
	
	
	
	$('.cash-btn').on('tap',function(){
		console.log(nowMoney)
		var toMoney = $('#cash-tomoney').children().eq(1).val();
		var toNum = $('#cash-Nummoney').children().eq(1).val();
		console.log(toMoney);
		console.log(toNum);
		console.log(myCountChoose);
		if(toMoney>nowMoney){
			mui.toast('余额不足！');
			return false;
		};	
		mui.confirm('请确认账号信息无误！', null, function(e) {
			if(e.index==1){
				userToMoney({
					c_user_id:CD.geturl().business,
					price:toMoney,
					account:toNum,
					account_type:myCountChoose
				},function(data){
					console.log(data.code)
					if(data.code==200){
						mui.toast('提现成功！')
					}else{
						mui.toast('提现失败！')
					}
				});
			}else{
				
			}
		})
	});
})

//提现
var userToMoney = function(params,callback){
	$.ajax({
		type: "get",
		cache: false,
		traditional: true,
		dataType: "json",
		url: window.address + "/wechat/inte/withdraw",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: params,
		success: function(data) {
			console.log(data);
			callback && callback(data);
		}
	});
}

//余额
var balance = function(params, callback) {
	$.ajax({
		type: "get",
		cache: false,
		traditional: true,
		dataType: "json",
		url: window.address + "/wechat/inte/seachInte",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: params,
		success: function(data) {
			console.log(data);
			callback && callback(data);
		}
	});
}